
import { createI18n } from 'vue-i18n';
import { localeMap } from './config';
import { setHtmlPageLang, setLoadLocalePool } from './helper';
import { useLocaleStoreWithOut } from '@/store/modules/locale';

interface obj {
  [propsName: string]: any
}
const createI18nOptions = async () => {
  const localeStore = useLocaleStoreWithOut();
  const locale = localeStore.getLocale || 'zh_CN';
  console.log(locale, 'locale1111');
  const defaultLocal = await import(`./lang/${locale}.ts`);
  const message = defaultLocal.default?.message ?? {};

  setHtmlPageLang(locale);
  setLoadLocalePool((loadLocalePool) => {
    loadLocalePool.push(locale);
  });

  return {
    locale,
    // legacy: false,
    fallbackLocale: localeMap.zh_CN, // set fallback locale
    messages: {
      [locale]: message as { [key: string]: string },
    },
    globalInjection: true,
    silentTranslationWarn: true, // true - warning off
    missingWarn: false,
    silentFallbackWarn: true,
  };
}
let resp: obj = ({})
const options = async () => {
  await createI18nOptions().then((res: obj) => {
    resp = res
  });
};
const i18n = createI18n(resp);
export default i18n
// setup i18n instance with global

